package com.easy;

/**
 * Created by Lxk on 2020/2/1.
 */
public class Solution108 {

    private TreeNode buildSearchTree(int begin, int end, int[] nums) {
        if (begin > end) {
            return null;
        }
        int mid = (begin + end) / 2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = buildSearchTree(begin, mid - 1, nums);
        node.right = buildSearchTree(mid + 1, end, nums);
        return node;
    }

    public TreeNode sortedArrayToBST(int[] nums) {
        return buildSearchTree(0, nums.length - 1, nums);
    }

    public static void main(String[] args) {
        int[] arr = {-10, -3, 0, 5, 9};
        Solution108 solution108 = new Solution108();
        TreeNode root = solution108.sortedArrayToBST(arr);
        System.out.println(root);
    }
}
